<template>
	<view>
		<view style="background-color: #fff;border-bottom: 1px solid #f4f4f4;">
			<u-tabs :list="list" :current="current" @click="change"></u-tabs>
		</view>

		<RecommendList v-if="current ==0" :list="infoList" />
		<MarketInfoList :list="infoList" v-else />


	</view>
</template>
<script>
	import RecommendList from "@/pages/components/RecommendList.vue";
	import MarketInfoList from "@/pages/components/MarketInfoList.vue";
	export default {
		name: 'index',
		components: {
			MarketInfoList,
			RecommendList
		},
		data() {
			return {
				current: 0,
				list: [],
				cid: 0,
				infoList: [],
				page: 1,
				total: 0
			}
		},
		onLoad() {
			this.get_cate()
			this.get_info()
		},
		onReachBottom() {
			if (this.page < this.total) {
				this.page++
				this.get_info()
			}
		},
		methods: {
			change(item) {
				console.log(item)
				this.current = item.index
				this.cid = this.list[this.current].id
				this.get_info()
			},
			get_cate() {
				this.$.ajax(1, "POST", "index/getnewcategory", {}, (res) => {
					if (res.code == 1) {
						this.list = res.data
					}
				})
			},
			get_info() {
				this.$.ajax(1, "POST", "index/getnewlist", {
					cid: this.cid,
					page: this.page
				}, (res) => {
					if (res.code == 1) {
						this.total = res.data.total
						if (this.page == 1) {
							this.infoList = []
						}
						this.infoList = [...this.infoList, ...res.data.list]
					} else {
						this.$.ti_shi(res.msg)
					}
				})
			}
		},
		created() {

		},
		mounted() {

		},
	}
</script>
<style>

</style>